package com.mentaleye.biz.impl;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mentaleye.bean.StudentDisciplineBean;
import com.mentaleye.biz.StudentDisciplineBiz;
import com.mentaleye.dal.model.StudentDiscipline;
import com.mentaleye.service.StudentDisciplineService;
import com.mentaleye.util.CommonPage;
import com.mentaleye.util.CommonResult;
import com.mentaleye.util.ObjectUtil;

@Service
public class StudentDisciplineBizImpl implements StudentDisciplineBiz {

	private static Logger logger = Logger.getLogger(StudentDisciplineBiz.class);
	
	@Autowired private StudentDisciplineService dataService;
	
	@Override
	public CommonResult insertRecord(StudentDisciplineBean dataBean) {
		CommonResult result=new CommonResult();
		try {
			StudentDiscipline data=(StudentDiscipline) ObjectUtil.transfer(dataBean, StudentDiscipline.class);
			if(this.dataService.insertRecord(data)){
				result.setIsSuccess(true);
				result.setResultMsg("添加成功！");
			}
			else
			{
				result.setResultMsg("添加失败！");
			}
		} catch (Exception e) {
			result.setResultMsg("添加异常！");
			logger.error("学生违纪信息添加异常！",e);
		}
		return result;
	}

	@Override
	public CommonResult updateRecord(StudentDisciplineBean dataBean) {
		CommonResult result=new CommonResult();
		try {
			StudentDiscipline data=(StudentDiscipline) ObjectUtil.transfer(dataBean, StudentDiscipline.class);
			if(this.dataService.updateRecord(data)){
				result.setIsSuccess(true);
				result.setResultMsg("更新成功！");
			}
			else
			{
				result.setResultMsg("更新失败！");
			}
		} catch (Exception e) {
			result.setResultMsg("更新异常！");
			logger.error("学生违纪信息更新异常！",e);
		}
		return result;
	}

	@Override
	public StudentDisciplineBean getBeanByKey(int id) {
		StudentDisciplineBean disciplineBean=null;
		try {
			disciplineBean=(StudentDisciplineBean) ObjectUtil.transfer(this.dataService.getRecordById(id), StudentDisciplineBean.class);
		} catch (Exception e) {
			logger.error("学生违纪信息查询异常！",e);
		}
		return disciplineBean;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<StudentDisciplineBean> getBeanList() {
		List<StudentDisciplineBean> beanList=null;
		try {
			beanList = ObjectUtil.transferList(this.dataService.getList(), StudentDisciplineBean.class);
		} catch (Exception e) {
			logger.error("学生违纪信息查询异常！",e);
		}
		return beanList;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<StudentDisciplineBean> getListByType(int typeId) {
		List<StudentDisciplineBean> beanList=null;
		try {
			beanList = ObjectUtil.transferList(this.dataService.getListByType(typeId), StudentDisciplineBean.class);
		} catch (Exception e) {
			logger.error("学生违纪信息查询异常！",e);
		}
		return beanList;
	}
	
	@Override
	public List<StudentDiscipline> getList() {
		List<StudentDiscipline> list=null;
		try {
			list = this.dataService.getList();
		} catch (Exception e) {
			logger.error("学生违纪信息查询异常！",e);
		}
		return list;
	}

	@Override
	public void getListByPage(CommonPage page) {
		List<Map<String,Object>> dataList =null;
        try {
			dataList = this.dataService.getListByMap(page.pageToMap());
			page.setPageData(dataList);
		} catch (Exception e) {
			logger.error("分页读取学生违纪信息异常！",e);
		}
	}

	@Override
	public CommonResult deleteByList(List<Integer> idList) {
		CommonResult result=new CommonResult();
        try {
			if(this.dataService.deleteByList(idList)){
				result.setIsSuccess(true);
				result.setResultMsg("删除成功！");
			}
			else
			{
				result.setResultMsg("删除失败！");
			}
		} catch (Exception e) {
			result.setResultMsg("删除异常！");
			logger.error("学生违纪信息删除异常！",e);
		}
		return result;
	}
}
